<?php

/*
 * File  : aksi_modul.php
 * Table : moduls
 */
session_start();
//cek session

if ((!$_SESSION["USRID"] AND !$_SESSION["USRPASS"]) OR $_SESSION["USRLEVEL"] != "admin") {
    header("location: ../index.php");
    exit();
}
//end
?>

<?php

include "../../../library/fungsi.lib.php";

$module = $_GET["module"];
$opr = $_GET["opr"];

// Hapus modul
if ($module == 'modul' AND $opr == 'hapus') {
    mysql_query("DELETE FROM modul WHERE id_modul='$_GET[id]'");
    header('location:' . URLHOST . 'cms/hansip.php?module=' . $module);
}

// Input modul
elseif ($module == 'modul' AND $opr == 'input') {
    // Cari angka urutan terakhir
    $u = mysql_query("SELECT mod_urutan FROM moduls ORDER by mod_urutan DESC");
    $d = mysql_fetch_array($u);
    $urutan = $d["mod_urutan"] + 1;

    $mod_nama = anti_injection($_POST["in_mod_nama"]);
    $mod_link = anti_injection($_POST["in_mod_link"]);
    $mod_aktif = $_POST["in_mod_aktif"];
    $mod_urutan = $urutan;

    // Input data modul
    $sql = "INSERT INTO moduls(mod_nama, mod_link, mod_aktif, mod_urutan)
            VALUES('$mod_nama', '$mod_link', '$mod_aktif', '$mod_urutan')";
    //echo $sql;
    mysql_query($sql);
    header('location:' . URLHOST . 'cms/hansip.php?module=' . $module);
}

// Update modul
elseif ($module == 'modul' AND $opr == 'update') {

    $mod_nama = anti_injection($_POST["in_mod_nama"]);
    $mod_link = anti_injection($_POST["in_mod_link"]);
    $mod_aktif = $_POST["in_mod_aktif"];
    $mod_urutan = $_POST["in_mod_urutan"];
    $mod_id = $_POST["id"];

    $sql = "UPDATE moduls SET mod_nama = '$mod_nama',
                                mod_link       = '$mod_link',
                                mod_aktif      = '$mod_aktif',
                                mod_urutan     = '$mod_urutan'  
                          WHERE mod_id = '$mod_id'";
    //echo $sql;
    mysql_query($sql);

    header('location:' . URLHOST . 'cms/hansip.php?module=' . $module);
}
?>
